#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

"""
@author: JoeyZhou
@Tool: PyCharm
@Date: 2020/2/17 10:03 AM
@desc: 数据库查询
"""

from base.sql_base import SqlBase


class SqlQuery:

    # 获取所有信息实例
    """
    def query_all(self):

        self.cur = SqlBase().mysql_connect()
        sql = "select * from account_pjt where env='uat' and user_name='吴彦祖';"
        sq.cur[0].execute(sql)
        data = self.cur[0].fetchall()
        self.cur[0].close()
        self.cur[1].close()
        return data[0][2],data[0][3]
    """

    # 获取单条信息实例
    """
    def query_only(self):

        self.cur = SqlBase().mysql_connect()
        sql = "select * from account_pjt where env='uat' and user_name='吴彦祖';"
        sq.cur[0].execute(sql)
        data = self.cur[0].fetchone()
        self.cur[0].close()
        self.cur[1].close()
        return data[2],data[3]
    """

    def query_venv(self, env):
        """
        查询测试环境
        :return:
        """
        cur = SqlBase().mysql_connect()
        sql = "select * from env_test where env='{}';".format(env)
        # 执行SQL语句(放到游标中)
        cur[0].execute(sql)
        # 获取指定的返回结果行
        data = cur[0].fetchone()
        # 0是游标，1是数据库
        cur[0].close()
        cur[1].close()
        return data[2]

    def query_account(self, env, username):
        """
        查询用户名和密码
        :return:
        """
        cur = SqlBase().mysql_connect()
        sql = "select * from account_pjt where env='{}' and user_name='{}';".format(env, username)
        cur[0].execute(sql)
        data = cur[0].fetchone()
        cur[0].close()
        cur[1].close()
        return data[2], data[3]


if __name__ == '__main__':
    sq = SqlQuery()
    print(sq.query_venv(env='uat'))
    print(sq.query_account(env='uat', username='吴彦祖'))
